<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js">&quot;use strict&quot;;
Object.defineProperty(exports, &quot;__esModule&quot;, { value: true });
exports.AnchorTagBuilder = void 0;
var html_tag_1 = require(&quot;./html-tag&quot;);
var truncate_smart_1 = require(&quot;./truncate/truncate-smart&quot;);
var truncate_middle_1 = require(&quot;./truncate/truncate-middle&quot;);
var truncate_end_1 = require(&quot;./truncate/truncate-end&quot;);
<span id='Autolinker-AnchorTagBuilder'>/**
</span> * @protected
 * @class Autolinker.AnchorTagBuilder
 * @extends Object
 *
 * Builds anchor (&amp;lt;a&amp;gt;) tags for the Autolinker utility when a match is
 * found.
 *
 * Normally this class is instantiated, configured, and used internally by an
 * {@link Autolinker} instance, but may actually be used indirectly in a
 * {@link Autolinker#replaceFn replaceFn} to create {@link Autolinker.HtmlTag HtmlTag}
 * instances which may be modified before returning from the
 * {@link Autolinker#replaceFn replaceFn}. For example:
 *
 *     var html = Autolinker.link( &quot;Test google.com&quot;, {
 *         replaceFn : function( match ) {
 *             var tag = match.buildTag();  // returns an {@link Autolinker.HtmlTag} instance
 *             tag.setAttr( &#39;rel&#39;, &#39;nofollow&#39; );
 *
 *             return tag;
 *         }
 *     } );
 *
 *     // generated html:
 *     //   Test &lt;a href=&quot;http://google.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;google.com&lt;/a&gt;
 */
var AnchorTagBuilder =  (function () {
<span id='Autolinker-AnchorTagBuilder-method-constructor'>    /**
</span>     * @method constructor
     * @param {Object} [cfg] The configuration options for the AnchorTagBuilder instance, specified in an Object (map).
     */
    function AnchorTagBuilder(cfg) {
        if (cfg === void 0) { cfg = {}; }
<span id='Autolinker-AnchorTagBuilder-cfg-newWindow'>        /**
</span>         * @cfg {Boolean} newWindow
         * @inheritdoc Autolinker#newWindow
         */
        this.newWindow = false; // default value just to get the above doc comment in the ES5 output and documentation generator
<span id='Autolinker-AnchorTagBuilder-cfg-truncate'>        /**
</span>         * @cfg {Object} truncate
         * @inheritdoc Autolinker#truncate
         */
        this.truncate = {}; // default value just to get the above doc comment in the ES5 output and documentation generator
<span id='Autolinker-AnchorTagBuilder-cfg-className'>        /**
</span>         * @cfg {String} className
         * @inheritdoc Autolinker#className
         */
        this.className = &#39;&#39;; // default value just to get the above doc comment in the ES5 output and documentation generator
        this.newWindow = cfg.newWindow || false;
        this.truncate = cfg.truncate || {};
        this.className = cfg.className || &#39;&#39;;
    }
<span id='Autolinker-AnchorTagBuilder-method-build'>    /**
</span>     * Generates the actual anchor (&amp;lt;a&amp;gt;) tag to use in place of the
     * matched text, via its `match` object.
     *
     * @param match The Match instance to generate an anchor tag from.
     * @return The HtmlTag instance for the anchor tag.
     */
    AnchorTagBuilder.prototype.build = function (match) {
        return new html_tag_1.HtmlTag({
            tagName: &#39;a&#39;,
            attrs: this.createAttrs(match),
            innerHtml: this.processAnchorText(match.getAnchorText()),
        });
    };
<span id='Autolinker-AnchorTagBuilder-method-createAttrs'>    /**
</span>     * Creates the Object (map) of the HTML attributes for the anchor (&amp;lt;a&amp;gt;)
     *   tag being generated.
     *
     * @protected
     * @param match The Match instance to generate an anchor tag from.
     * @return A key/value Object (map) of the anchor tag&#39;s attributes.
     */
    AnchorTagBuilder.prototype.createAttrs = function (match) {
        var attrs = {
            href: match.getAnchorHref(), // we&#39;ll always have the `href` attribute
        };
        var cssClass = this.createCssClass(match);
        if (cssClass) {
            attrs[&#39;class&#39;] = cssClass;
        }
        if (this.newWindow) {
            attrs[&#39;target&#39;] = &#39;_blank&#39;;
            attrs[&#39;rel&#39;] = &#39;noopener noreferrer&#39;; // Issue #149. See https://mathiasbynens.github.io/rel-noopener/
        }
        if (this.truncate) {
            if (this.truncate.length &amp;&amp; this.truncate.length &lt; match.getAnchorText().length) {
                attrs[&#39;title&#39;] = match.getAnchorHref();
            }
        }
        return attrs;
    };
<span id='Autolinker-AnchorTagBuilder-method-createCssClass'>    /**
</span>     * Creates the CSS class that will be used for a given anchor tag, based on
     * the `matchType` and the {@link #className} config.
     *
     * Example returns:
     *
     * - &quot;&quot;                                      // no {@link #className}
     * - &quot;myLink myLink-url&quot;                     // url match
     * - &quot;myLink myLink-email&quot;                   // email match
     * - &quot;myLink myLink-phone&quot;                   // phone match
     * - &quot;myLink myLink-hashtag&quot;                 // hashtag match
     * - &quot;myLink myLink-mention myLink-twitter&quot;  // mention match with Twitter service
     *
     * @protected
     * @param match The Match instance to generate an
     *   anchor tag from.
     * @return The CSS class string for the link. Example return:
     *   &quot;myLink myLink-url&quot;. If no {@link #className} was configured, returns
     *   an empty string.
     */
    AnchorTagBuilder.prototype.createCssClass = function (match) {
        var className = this.className;
        if (!className) {
            return &#39;&#39;;
        }
        else {
            var returnClasses = [className], cssClassSuffixes = match.getCssClassSuffixes();
            for (var i = 0, len = cssClassSuffixes.length; i &lt; len; i++) {
                returnClasses.push(className + &#39;-&#39; + cssClassSuffixes[i]);
            }
            return returnClasses.join(&#39; &#39;);
        }
    };
<span id='Autolinker-AnchorTagBuilder-method-processAnchorText'>    /**
</span>     * Processes the `anchorText` by truncating the text according to the
     * {@link #truncate} config.
     *
     * @private
     * @param anchorText The anchor tag&#39;s text (i.e. what will be
     *   displayed).
     * @return The processed `anchorText`.
     */
    AnchorTagBuilder.prototype.processAnchorText = function (anchorText) {
        anchorText = this.doTruncate(anchorText);
        return anchorText;
    };
<span id='Autolinker-AnchorTagBuilder-method-doTruncate'>    /**
</span>     * Performs the truncation of the `anchorText` based on the {@link #truncate}
     * option. If the `anchorText` is longer than the length specified by the
     * {@link #truncate} option, the truncation is performed based on the
     * `location` property. See {@link #truncate} for details.
     *
     * @private
     * @param anchorText The anchor tag&#39;s text (i.e. what will be
     *   displayed).
     * @return The truncated anchor text.
     */
    AnchorTagBuilder.prototype.doTruncate = function (anchorText) {
        var truncate = this.truncate;
        if (!truncate || !truncate.length)
            return anchorText;
        var truncateLength = truncate.length, truncateLocation = truncate.location;
        if (truncateLocation === &#39;smart&#39;) {
            return (0, truncate_smart_1.truncateSmart)(anchorText, truncateLength);
        }
        else if (truncateLocation === &#39;middle&#39;) {
            return (0, truncate_middle_1.truncateMiddle)(anchorText, truncateLength);
        }
        else {
            return (0, truncate_end_1.truncateEnd)(anchorText, truncateLength);
        }
    };
    return AnchorTagBuilder;
}());
exports.AnchorTagBuilder = AnchorTagBuilder;
//# sourceMappingURL=anchor-tag-builder.js.map</pre>
</body>
</html>
